import time

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains
class Base():
    def __init__(self,dr):
        self.dr=dr
    def get_url(self,url):
        self.dr.get(url)
    def find_element(self,loc):
        try:
            WebDriverWait(self.dr,20,0.5).until(lambda dr:self.dr.find_element(*loc).is_displayed())
            return self.dr.find_element(*loc)
        except Exception as e:
            print(e)
    def click(self,loc):
        self.find_element(loc).click()
    def send_keys(self,loc,info):
        self.find_element(loc).send_keys(info)
    def text(self,loc):
        return self.find_element(loc).text
    def sleep(self,s):
        time.sleep(s)
    def kj(self,loc):
        a=self.find_element(loc)
        self.dr.switch_to.frame(a)
    def tcu(self):
        self.dr.switch_to.default_content()
    def hd(self,s):
        self.dr.execute_script(f'window.scrollTo(0,{s})')
    def qh(self):
        self.dr.switch_to.window(self.dr.window_handles[-1])
    def qd(self,loc,s):
        a=Select(self.find_element(loc))
        a.select_by_value(s)
    def tc(self):
        a=self.dr.switch_to.alert
        a.accept()
    def sj(self,loc):
        ActionChains(self.dr).double_click(self.find_element(loc))
    def hc(self,loc):
        self.send_keys(loc,Keys.ENTER)